//--------------------------------------------------------------------
#ifndef _dkevents_h
#define _dkevents_h
//--------------------------------------------------------------------
#include <stdio.h>
//--------------------------------------------------------------------


//--------------------------------------------------------------------
// error handlers (ON ERROR x GOTO y)
struct _dk_errorhandler
{
	uint8_t errornum;				// error #
	uint16_t linenum;				// line # of the error handler
	
	struct _dk_errorhandler *next;	// next errorhandler in list
};
//--------------------------------------------------------------------

// error handlers (ON ERROR x GOTO y)
extern struct _dk_errorhandler *dk_errorhandlers;


//--------------------------------------------------------------------
#define NUM_COM_HANDLERS	2
#define NUM_KEY_HANDLERS	20
#define NUM_TIMER_HANDLERS	8
#define NUM_PIN_HANDLERS	16

#define DK_EVENT_COM0		(1<<0)
#define DK_EVENT_COM1		(1<<1)
#define DK_EVENT_KEY		(1<<2)
#define DK_EVENT_TIMER		(1<<3)
#define DK_EVENT_PIN		(1<<4)

//--------------------------------------------------------------------

extern volatile uint8_t dkeventflags;		// bitmapped for each type of event that is enabled
extern uint8_t dkeventmasks;

extern uint8_t dkevent_key;		// set to value of last KEY event (only most recent KEY event is kept)

extern uint16_t dkevent_com_handlers[NUM_COM_HANDLERS];		// line number for handlers for COM0: and COM1:
extern uint16_t dkevent_key_handlers[NUM_KEY_HANDLERS];		// event handlers 1-20 for KEY()
extern uint16_t dkevent_timer_handlers[NUM_TIMER_HANDLERS];	// handler for TIMER()
extern uint16_t dkevent_pin_handlers[NUM_PIN_HANDLERS];		// handler for PIN()

extern uint16_t dkpin_flags;		// bitmapped for 16 PIN events
extern uint16_t dkpin_masks;

struct _dkpin
{
	uint16_t addr;			// address of PINx register
	uint8_t bit;			// which bit is this pin?
	uint8_t value;			// 0 = low level, 1 = high level, bit 7=previously sampled pin value
};

extern struct _dkpin dkpins[ NUM_PIN_HANDLERS ];



int dkhandle_event( void );

//--------------------------------------------------------------------
#endif	// !_dkevents_h
//--------------------------------------------------------------------
